<?php
 require_once("../includes/config.php"); 

$filename = "client".'-'.date('d.m.Y').'.csv';
                // Get backup data from MYSQL database
                $result_users =query('SELECT name, identification_number,identification_type ,mobile ,email FROM clients');
				// Create array
            $list = array ();

            // Append results to array
            array_push($list, array("## START OF USER TABLE ##"));
            foreach($result_users as $row) {
                array_push($list, array_values($row));
            }
            array_push($list, array("## END OF USER TABLE ##"));

            // Output array into CSV file
            $fp = fopen('php://output', 'w');
            header('Content-Type: text/csv');
            header('Content-Disposition: attachment; filename="'.$filename.'"');
            foreach ($list as $ferow) {
                fputcsv($fp, $ferow);
            }
?>